//
//  ForumDetailVC.m
//  BaseProject
//
//  Created by hundredsandc on 2017/10/30.
//  Copyright © 2017年 hundredsandc. All rights reserved.
//

#import "ForumDetailVC.h"
#import "AllCommentVC.h"

@interface ForumDetailVC ()<UIWebViewDelegate>
@property (nonatomic, strong)UIWebView * myWebView;
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic,strong)UILabel *commentCount;
@property (nonatomic,strong)UILabel *likeCount;
@property (nonatomic,strong)UIButton *likeBtn;
@property (nonatomic,strong)UIButton *commentBtn;

@end

@implementation ForumDetailVC

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.myWebView = [[UIWebView alloc]init];
    self.myWebView.delegate = self;
    self.myWebView.x = 0;
    self.myWebView.y = 30;
    self.myWebView.width = GetWidth;
    self.myWebView.height = GetHeight - 64-30;
    
    
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:self.url]];
    
    [self.myWebView loadRequest:request];
    
    [self.view addSubview:self.myWebView];
    
    [self addHeaderView];
    
    
}
-(void)addHeaderView{
    UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    header.backgroundColor = RGBCOLOR(0xf3, 0xf4, 0xf5);
    
    _commentCount = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-32-10, (30-13)/2, 32, 13)];
    _commentCount.font =FONT(12);
    _commentCount.text= @"2222";
    
    _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_commentBtn addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
    _commentBtn.frame = CGRectMake(_commentCount.left-13-10, _commentCount.y, 13, 13);
    [_commentBtn setBackgroundImage:[UIImage imageNamed:@"pinglun"] forState:UIControlStateNormal];
    
    _likeCount = [[UILabel alloc]initWithFrame:CGRectMake(_commentBtn.left-10-32, (30-13)/2, 32, 13)];
    _likeCount.font =FONT(12);
    _likeCount.text= @"333";
    
    _likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_likeBtn addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
    _likeBtn.frame = CGRectMake(_likeCount.left-13-10, _commentCount.y, 13, 13);
    [_likeBtn setBackgroundImage:[UIImage imageNamed:@"xingxing"] forState:UIControlStateNormal];
    
    [header addSubview:_commentCount];
    [header addSubview:_commentBtn];
    [header addSubview:_likeCount];
    [header addSubview:_likeBtn];
    
    [self.view addSubview:header];
}
-(void)likeClick{

}
-(void)commentClick{
    AllCommentVC *all = [AllCommentVC new];
    [self.navigationController pushViewController:all animated:YES];
}
-(void)popBtnClick{
    if ([self.myWebView canGoBack]) {
        [self.myWebView goBack];
    }else{
        
        NSHTTPCookie *cookie;
        NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (cookie in [storage cookies])
        {
            [storage deleteCookie:cookie];
        }
        [[NSURLCache sharedURLCache] removeAllCachedResponses];
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    if (self.titleStr.length==0) {
        
        self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    }
}


@end
